<div class="main-content">
    <div class="section__content section__content--p20">
        <div class="container-fluid">
            <div class="row m-b-30">
                <div class="col-lg-12">
                    <div class="overview-wrap">
                        <h2 class="title-1">内容管理</h2>
                        <div class="form-inline">
                            <div class="form-group m-r-5">
                                <button class="au-btn au-btn-icon au-btn--blue" onclick="showedit(0)">
                                    <i class="zmdi zmdi-plus"></i>新建内容</button>
                            </div>
                            <div class="form-group">
                                <select class="form-control-lg" name="type" onchange="changeType()">
                                    <option value="article" <?php echo $type == 'article' ? "selected='selected'" : "" ?> >文章</option>
                                    <option value="download" <?php echo $type == 'download' ? "selected='selected'" : "" ?> >下载</option>
                                    <option value="job" <?php echo $type == 'job' ? "selected='selected'" : "" ?> >招聘</option>
                                    <option value="image" <?php echo $type == 'image' ? "selected='selected'" : "" ?> >图片</option>
                                    <option value="product" <?php echo $type == 'product' ? "selected='selected'" : "" ?> >产品</option>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-lg-12">
                    <div class="table-responsive table--no-card m-b-30">
                        <table class="table table-borderless table-striped table-earning">
                            <thead>
                            <tr>
                                <th>标题</th>
                                <th>排序</th>
                                <th>栏目</th>
                                <th>推荐</th>
                                <th>置顶</th>
                                <th>更新时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php
                            if (sizeof($list) > 0) {
                                foreach ($list as $l) {
                                    ?>
                                    <tr>
                                        <td><?php echo $l['title']; ?></td>
                                        <td><?php echo $l['seq']; ?></td>
                                        <td><?php echo $l->module->category; ?></td>
                                        <td><?php echo $l['recommend'] == 0 ? "否" : "是"; ?></td>
                                        <td><?php echo $l['top'] == 0 ? "否" : "是"; ?></td>
                                        <td><?php echo $l['createtime']; ?></td>
                                        <td>
                                            <button type="button" class="btn btn-primary btn-sm"
                                                    onclick="showedit(<?php echo $l['article_id']; ?>)" >编辑</button>
                                            <button type="button"  data-toggle="modal" data-target="#confirmModal"  class="btn btn-danger btn-sm" onclick="del(<?php echo $l['article_id']; ?>)">删除</button>

                                        </td>
                                    </tr>
                                    <?php
                                }
                            }
                            ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
            <div class="row ">
                <div class="col-lg-12 text-center">
                    <div style="display: inline-block;"><?php
                        $this->widget('CLinkPager', array(
                                'header' => '',
                                'firstPageLabel' => '首页',
                                'lastPageLabel' => '末页',
                                'prevPageLabel' => '上一页',
                                'nextPageLabel' => '下一页',
                                'pages' => $pages,
                                "selectedPageCssClass"=>'active',
                                'htmlOptions' => Array('class' => 'pagination pagination_customize')
                            )
                        );
                        ?></div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $(function () {
        initPage();
    });
    function initPage() {
        paginationLoad();
    }
    function showedit(id) {
        var type = $("select[name=type]").val();
        if (id == 0) {
            window.location.href = "index.php?r=admin/" + type + "/add&id=" + id;
            return;
        }
        window.location.href = "index.php?r=admin/" + type + "/showedit&id=" + id;
    }
    function del(id) {
        /*confirm("确定删除内容？",function () {
            var type = $("select[name=type]").val();
            $.get('index.php?r=admin/' + type + '/del', {id: id}, function (result) {
                if(message(result)){
                    window.location.href = "index.php?r=admin/content/index&type="+type;
                }
            }, 'json');
        });*/
        $("#confirmModal_text").text('确定删除内容？');
        var type = $("select[name=type]").val();
        $("#confirmModalButton").bind("click",function () {
            $.get('index.php?r=admin/' + type + '/del', {id: id}, function (result) {
                if(message(result)){
                    window.location.href = "index.php?r=admin/content/index&type="+type;
                }
            }, 'json');
        });
    }
    function changeType() {
        var type = $("select[name=type]").val();
        window.location.href = "index.php?r=admin/content/index&type="+type;
    }
</script>